﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class XeDao
    {
        public int LayMa()
        {
            DoixeDataContext DX = new DoixeDataContext();

            int Lable;
            Lable = 0;
            int MA = 0;
            while (Lable == 0)
            {
                IEnumerable<XE> xDto;
                xDto = from x in DX.XEs where x.MaXe == MA select x;
                if (xDto.Count() != 0)
                {
                    MA++;
                }
                else
                {
                    Lable = 1;
                }
            }
            return MA;
        }
        public void TiepNhanXe(XE X)
        {
            DoixeDataContext DX = new DoixeDataContext();
            DX.XEs.InsertOnSubmit(X);
            DX.SubmitChanges();
        }
        public IEnumerable<XE> LayXe(int Ma)
        {

            DoixeDataContext DX = new DoixeDataContext();
            IEnumerable<XE> xDto;
            xDto = from x in DX.XEs where x.MaXe == Ma select x;
            return xDto;
        }
        public IEnumerable<XE> TimKiem( string BienSo,string HieuXe, string SoKhung, string SoMay)
        {
            DoixeDataContext DX = new DoixeDataContext();
            IEnumerable<XE> xDto;
            xDto = from x in DX.XEs where x.BienSo.Contains(BienSo)==true && x.HieuXe.Contains(HieuXe) &&x.SoKhung.Contains(SoKhung)&&x.SoMay.Contains(SoMay) select x;
            return xDto;
        }
    }
}
